/*
 * Copyright (c) Howard Chan, Vicente de Rivera III
 * All rights reserved
 */
package com.taxi;

import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.taxi.service.TaxiService;

/**
 * @author thirdy
 */
public class Main implements Application {
    public static MainController mainController = null;
    public static Display display;
    
    private static TaxiService taxiService;
    
    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        Main.display = display;
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        mainController = (MainController) bxmlSerializer.readObject(Main.class, "main.bxml");
        // init controllers
        mainController.setTaxiService(taxiService);
        // show the ui
        mainController.setMaximized(true);
        mainController.open(display);
    }
    @Override
    public boolean shutdown(boolean optional) {
        if (mainController != null)
            mainController.close();
        return false;
    }
    @Override
    public void suspend() {}
    @Override
    public void resume() {}
    
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        taxiService = (TaxiService) context.getBean("taxiService");
        DesktopApplicationContext.main(Main.class, args);
    }
  
}